// change directory
use "OPI - Data published.dta",clear

/* Column 1 of Table 1. Please note that the results must be multiplied by 100 to get percentages. */
asdoc sum ans1 if ans1<3,replace stat(mean )
quietly forvalues n=2/116 {
asdoc sum ans`n'  if ans`n'<3, rowappend stat(mean)
}

/* The test results for column 5 of Table 1 */
quietly forvalues n=1/116 {
gen ans`n'b=ans`n'
replace ans`n'b=. if ans`n'b==3
}

asdoc	prtest	ans1b==	0.04,   replace  stat(obs mean t p )
asdoc	prtest	ans2b==	0.03	,  rowappend stat(obs mean t p )
asdoc	prtest	ans3b==	0.1	,  rowappend stat(obs mean t p )
asdoc	prtest	ans4b==	0.19	,  rowappend stat(obs mean t p )
asdoc	prtest	ans5b==	0.91	,  rowappend stat(obs mean t p )
asdoc	prtest	ans7b==	0.85	,  rowappend stat(obs mean t p )
asdoc	prtest	ans8b==	0.17	,  rowappend stat(obs mean t p )
asdoc	prtest	ans9b==	0.35	,  rowappend stat(obs mean t p )
asdoc	prtest	ans10b==	0.57	,  rowappend stat(obs mean t p )
asdoc	prtest	ans11b==	0.38	,  rowappend stat(obs mean t p )
asdoc	prtest	ans12b==	0.22	,  rowappend stat(obs mean t p )
asdoc	prtest	ans17b==	0.42	,  rowappend stat(obs mean t p )
asdoc	prtest	ans18b==	0.72	,  rowappend stat(obs mean t p )
asdoc	prtest	ans20b==	0.71	,  rowappend stat(obs mean t p )
asdoc	prtest	ans22b==	0.8	,  rowappend stat(obs mean t p )
asdoc	prtest	ans23b==	0.8	,  rowappend stat(obs mean t p )
asdoc	prtest	ans26b==	0.09	,  rowappend stat(obs mean t p )
asdoc	prtest	ans31b==	0.07	,  rowappend stat(obs mean t p )
asdoc	prtest	ans33b==	0.61	,  rowappend stat(obs mean t p )
asdoc	prtest	ans34b==	0.44	,  rowappend stat(obs mean t p )
asdoc	prtest	ans35b==	0.43	,  rowappend stat(obs mean t p )
asdoc	prtest	ans36b==	0.7	,  rowappend stat(obs mean t p )
asdoc	prtest	ans37b==	0.37	,  rowappend stat(obs mean t p )
asdoc	prtest	ans38b==	0.49	,  rowappend stat(obs mean t p )
asdoc	prtest	ans40b==	0.14	,  rowappend stat(obs mean t p )
asdoc	prtest	ans43b==	0.27	,  rowappend stat(obs mean t p )
asdoc	prtest	ans44b==	0.28	,  rowappend stat(obs mean t p )
asdoc	prtest	ans45b==	0.24	,  rowappend stat(obs mean t p )
asdoc	prtest	ans48b==	0.52	,  rowappend stat(obs mean t p )
asdoc	prtest	ans50b==	0.86	,  rowappend stat(obs mean t p )
asdoc	prtest	ans51b==	0.31	,  rowappend stat(obs mean t p )
asdoc	prtest	ans52b==	0.43	,  rowappend stat(obs mean t p )
asdoc	prtest	ans55b==	0.33	,  rowappend stat(obs mean t p )
asdoc	prtest	ans56b==	0.91	,  rowappend stat(obs mean t p )
asdoc	prtest	ans57b==	0.56	,  rowappend stat(obs mean t p )
asdoc	prtest	ans61b==	0.95	,  rowappend stat(obs mean t p )
asdoc	prtest	ans62b==	0.87	,  rowappend stat(obs mean t p )
asdoc	prtest	ans66b==	0.47	,  rowappend stat(obs mean t p )
asdoc	prtest	ans67b==	0.03	,  rowappend stat(obs mean t p )
asdoc	prtest	ans68b==	0.8	,  rowappend stat(obs mean t p )
asdoc	prtest	ans86b==	0.79	,  rowappend stat(obs mean t p )
asdoc	prtest	ans87b==	0.38	,  rowappend stat(obs mean t p )
asdoc	prtest	ans89b==	0.16	,  rowappend stat(obs mean t p )
asdoc	prtest	ans93b==	0.54	,  rowappend stat(obs mean t p )
asdoc	prtest	ans94b==	0.43	,  rowappend stat(obs mean t p )
asdoc	prtest	ans95b==	0.29	,  rowappend stat(obs mean t p )
asdoc	prtest	ans97b==	0.79	,  rowappend stat(obs mean t p )
asdoc	prtest	ans110b==	0.12	,  rowappend stat(obs mean t p )
asdoc	prtest	ans111b==	0.16	,  rowappend stat(obs mean t p )
asdoc	prtest	ans113b==	0.22	,  rowappend stat(obs mean t p )
asdoc	prtest	ans114b==	0.37	,  rowappend stat(obs mean t p )
asdoc	prtest	ans115b==	0.16	,  rowappend stat(obs mean t p )

/* Column 6 */
forvalues v=1/116 {
sum ans`v' if ans`v'==3
}

/* Column 7 */
forvalues v=1/116 {
sum ans`v' if ans`v'!=3 & ans`v'!=. 
}

/* Column 4 of Table A2 in the appendix */
// m1 and s1
forvalues n=1/116 {
sum ans`n' if subsample==1 & ans`n'<3  
}
// m2 and s2
forvalues n=1/116 {
sum ans`n' if subsample==2 & ans`n'<3  
}

/* Column 1 of Table A3 in the appendix */
quietly foreach v of varlist ans1-ans116 {
	g tem=sum(`v'==3)
	replace tem=. if `v'~=3
	sum tem
	g `v'a=`v'
	replace `v'a=1 if `v'==3 & tem<=r(mean)
	replace `v'a=0 if `v'==3 & tem>r(mean)
	drop tem
}

asdoc sum ans1a ,replace stat(mean )
quietly forvalues n=2/116 {
asdoc sum ans`n'a , rowappend stat(mean)
}
